#!/bin/bash

# Command list
commands=(
    "sudo stty -F /dev/ttyCH9344USB2 115200"
    "sudo stty -F /dev/ttyCH9344USB2 -echo -icanon"
    "gpioset gpiochip0 4=0"
    "gpioset gpiochip0 5=0"
    "gpioset gpiochip0 13=0"
    "ifconfig"
    "i2cdetect -y 1"
    "lsblk"
    "./do0"
    "./spidev-GPB0"
    "./spidev-read_A0-A7"
    "./do1"
    "./spidev-GPB1"
    "./spidev-read_A0-A7"
    "./ads1115_example"
    "sudo hwclock -w"
    "sudo hwclock -r"
    "date"
)

delay=0.2  # 200ms

echo "Start execution..."
echo "==================="

for ((i=0; i<${#commands[@]}; i++)); do
    echo -e "\n[$((i+1))/${#commands[@]}] ${commands[$i]}"
    echo "-------------------"
    
    ${commands[$i]}
    
    # Wait if not the last command
    [ $i -lt $(( ${#commands[@]} - 1 )) ] && sleep $delay
done

echo -e "\n==================="
echo "All commands executed"
    